package com.lucene.blog.db.service.impl;

import java.sql.SQLException;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lucene.blog.bean.Blogger;
import com.lucene.blog.db.mapper.BloggerMapper;
import com.lucene.blog.db.service.BloggerService;
import com.lucene.blog.util.StringUtil;

@Service("bloggerService")
public class BloggerServiceImpl implements BloggerService {

	@Resource
	private BloggerMapper bloggerMapper;
	
	// 获取博主信息
	public Blogger getBloggerData() throws SQLException {
		return bloggerMapper.getBloggerData();
	}
	
	// 通过博主Id查询博主信息
	public Blogger getBloggerById(Integer bloggerId) throws SQLException {
		return bloggerMapper.getBloggerById(bloggerId);
	}
	
	// 通过昵称和密码查询博主信息
	public Blogger getBloggerByNickAndPass(Map<String, Object> nick_pass) throws SQLException {
		if(nick_pass.size() > 0 && nick_pass.size() == 2) {
			return bloggerMapper.getBloggerByNickAndPass(nick_pass);
		}
		return null;
	}
	
	// 通过昵称查询博主
	public Blogger getBloggerByNickname(String nickName) throws SQLException {
		if(StringUtil.isNotEmpty(nickName)) {
			return bloggerMapper.getBloggerByNickname(nickName);
		}
		return null;
	}
	
	// 更新博主个人信息
	public int updateBlogger(Blogger blogger) throws SQLException {
		if(blogger != null) {
			return bloggerMapper.updateBlogger(blogger);
		}
		return 0;
	}

}
